﻿@using ChiakiYu.Model.Permissions
@using ChiakiYu.Model.Roles
@model IEnumerable<RolePermission>
@{
    int roleId = Convert.ToInt32(ViewData["RoleId"]);
    var permissionsOfAssembly = ViewData.Get<List<Permission>>("PermissionsOfAssembly", null);
}

<div>
    @using (Html.BeginForm(MVC.Admin.AdminUser.ChangePermissions(), FormMethod.Post, new { role = "form" }))
    {
        <div class="panel-body" style="width: 600px; height: 400px; overflow-x: hidden;">
            @Html.AntiForgeryToken()
            @Html.Hidden("roleId", roleId)
            @if (permissionsOfAssembly != null && permissionsOfAssembly.Any())
            {
                var list = permissionsOfAssembly.Select(n => new {n.Controller, n.ControllerDescription}).Distinct();
                foreach (var item in list)
                {
                    var hehe = permissionsOfAssembly.Where(n => n.Controller == item.Controller);
                    <div class="row">
                        <div class="col-lg-3">
                            <label for="@item.Controller">
                                @item.ControllerDescription
                            </label>
                        </div>
                        <div class="col-lg-9">
                            @foreach (var h in hehe)
                            {
                                var hehess = Model != null && Model.FirstOrDefault(n => n.Controller == h.Controller && n.Action == h.Action ) != null;
                                <label for="action-@(h.Id)" style="margin-right: 30px;">
                                    <input type="checkbox" name="Id" id="action-@h.Id" value="@h.Id" checked="@(hehess)"/>
                                    @h.ActionDescription
                                </label>
                            }
                        </div>
                    </div>
                    <hr/>
                }
            }
        </div>
        <div class="panel-footer">
            <div class="text-center">
                <button type="submit" class="btn btn-success" plugin="ajaxSubmitDialog">保存</button>
            </div>
        </div>
    }
</div>